#pragma once
#include "refc_ptr.h"

namespace krryn{
namespace audio{
	class filter{
	public:
		typedef core::refc_ptr<filter> ptr;
		typedef float value_type;

		virtual void operator()(value_type *a_Data, int a_SampleRate, size_t a_Count) const = 0;
	};

	class filter_low_pass : public filter{
	public:
		filter_low_pass(value_type a_Frequency) : m_Frequency(a_Frequency){}

		virtual void operator()(value_type *a_Data, int a_SampleRate, size_t a_Count) const{
			value_type l_Length = a_Count / static_cast<value_type>(a_SampleRate);
			size_t l_FrequencyIndex = static_cast<size_t>(m_Frequency * l_Length);
			size_t l_Index = std::min(a_Count, l_FrequencyIndex);

			for(size_t i = 0; i < l_Index; i++){
				a_Data[i] = 0;
			}
		}
	private:
		const value_type m_Frequency;
	};

	class filter_high_pass : public filter{
	public:
		filter_high_pass(value_type a_Frequency) : m_Frequency(a_Frequency){}

		virtual void operator()(value_type *a_Data, int a_SampleRate, size_t a_Count) const{
			value_type l_Length = a_Count / static_cast<value_type>(a_SampleRate);
			size_t l_FrequencyIndex = static_cast<size_t>(m_Frequency * l_Length);
			size_t l_Index = std::min(a_Count, l_FrequencyIndex);

			for(size_t i = l_Index; i < a_Count; i++){
				a_Data[i] = 0;
			}
		}
	private:
		const value_type m_Frequency;
	};
}
}
